package com.ch07.service;

import com.ch07.container.ContainerFactory;

import java.math.BigDecimal;

/**
 * @ClassName PaymentContext
 * @Description TODO
 * @Author Kx
 * @Date 2025/4/17 10:47
 * @Version 1.0
 */
public class PaymentService {

    // 容器工厂
    private static final ContainerFactory factory = new ContainerFactory("com.ch07.service.impl");

    private Payment payment;

    /***
     * @author: kx
     * @date: 2025/4/17 11:19
     * @param pay :支付方式
     * @description: 构造方法传入一个支付的类型来决定实例化某一种支付策略
    */
    public PaymentService(String pay) {
        try {
            payment = (Payment) factory.getBean(pay);
        } catch (Exception e) {
            throw new RuntimeException("暂不支持该支付方式");
        }
    }
    
    /*** 
     * @author: kx
     * @date: 2025/4/17 11:18
     * @param pay : 金额
     * @description: 支付方式
    */
    public void pay(BigDecimal pay) {
        payment.pay(pay);
    }
}
